package com.my.db.test.mybatis;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.my.core.page.PageInfo;
import com.my.core.page.PageParam;
import com.my.db.test.mybatis.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author timo 2021/3/4
 */
@RestController
@RequestMapping("mybatistest")
@Slf4j
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/list")
    public List<Employee> findAll(){
        return employeeService.list(null);
    }
    @RequestMapping("/save")
    public Boolean save(@RequestBody Employee employee){
        employeeService.save(employee);
        return Boolean.TRUE;
    }
    @RequestMapping("/update")
    public Boolean update(@RequestBody Employee employee){
        employeeService.updateById(employee);
        return Boolean.TRUE;
    }

    @RequestMapping("/page")
    public PageInfo<Employee> page(PageParam pageParam, String id) {
        LambdaQueryWrapper queryWrapper2 = Wrappers.<Employee>lambdaQuery()
                .eq(Employee::getId, id)
                .last(" limit 1");
        LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(Employee.class)
                .eq(Employee::getId, id);
        PageInfo pageInfo = employeeService.selectPage(pageParam, queryWrapper);

        PageInfo<Employee> employeePageInfo = employeeService.queryOwenPage(pageParam, id);
        return employeePageInfo;
    }

}
